package com.wz.redistest;

import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

public class JedisConnector {
	private JedisPool pool = null;
	private static JedisConnector connector = null;

	public static JedisConnector getInstance(){
		if (connector == null){
			connector = new JedisConnector();
			connector.init();
		}
		return connector;
	}

	public JedisPool getPool() {
		return pool;
	}

	public void setPool(JedisPool pool) {
		this.pool = pool;
	}

	private void init(){
		JedisPoolConfig config = new JedisPoolConfig();
		config.setMaxActive(JedisConfig.MAX_ACTIVE);
		config.setMaxIdle(JedisConfig.MAX_IDLE);
		config.setMaxWait(JedisConfig.MAX_WAIT);
		config.setTestOnBorrow(JedisConfig.TEST_ON_BORROW);
		config.setTestOnReturn(JedisConfig.TEST_ONRE_TURN);
		pool = new JedisPool(config, JedisConfig.REDIS_IP, JedisConfig.REDIS_PORT);
	}

}